package com.sky.service.impl;

import com.sky.entity.Setmeal;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.service.UserSetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserSetmealServiceImpl implements UserSetmealService {
    @Autowired
    private SetmealMapper setmealMapper;
    @Autowired
    private DishMapper dishMapper;

    @Override
    public List userSetmealList(String categoryId) {
        List<Setmeal> setmeals = setmealMapper.getSetmealByCategoryId(categoryId);
        return setmeals;
    }

    @Override
    public List userSetmealDish(Integer id) {
        List<DishVO> dishesForUserBySetmealId = setmealMapper.getDishesForUserBySetmealId(id);
        List<DishItemVO> result = new ArrayList<>();

        for (DishVO dish : dishesForUserBySetmealId) {
            DishVO dishVO = dishMapper.getById(Math.toIntExact(dish.getId()));
            result.add(new DishItemVO(dishVO.getName(),dish.getCopies(),dishVO.getImage(),dishVO.getDescription())) ;
        }

        return result;
    }
}
